﻿using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using UtilsORM;
using UtilsORM.MySqlData;

////using System.Web.Script.Serialization;

namespace ServiceWeb.DBGateway
{
    public class DBIotDeviceGroup
    {
        EFYihongIotContext ef = new EFYihongIotContext();
        public List<iot_device_group> getList(string cguid)
        {
            return ef.iot_device_group.Where(c => c.g_status == 0 && c.g_c_guid == cguid).ToList();
        }
        public iot_device_group getGroup(string gguid)
        {
            return ef.iot_device_group.Where(c => c.g_guid == gguid).FirstOrDefault();
        }
        public bool saveAll(IFormCollection FC, HttpReqModel httpRequest, MagerLoginInfo LoginUserInfo, iot_device_group req)
        {
            //先查一下有没重复提交
            iot_device_group model = ef.iot_device_group.Where(c => c.g_guid == req.g_guid).FirstOrDefault();
            if (model == null)
            {

                req.g_add_time = DateTime.Now;
                req.g_c_guid = LoginUserInfo.userCompanyGuid;
                ef.iot_device_group.Add(req);
                ef.SaveChanges();
            }
            else
            {
                model.g_name = req.g_name;
                model.g_status = req.g_status;
                ef.iot_device_group.Update(model);
                ef.SaveChanges();
            }
            return true;
        }
    }
}
